# -*- coding:utf-8 -*-
# @FileName  :dhcc_per_8_alertpage.py
# @Time      :2020/12/23 15:37
# @Author    :Zhoujirong
# @Desc      : 预警信息
import datetime
import time

from common.log import Log
from common.utils import download
from biz.flow.per_alertpage import PerAlertPageRequest
from biz.cases.base_case import BaseCase
from biz.flow.per_rule import PerRuleRequest

class TestPerAlertPage(BaseCase):
    data_file_name = 'per_alertpage.yaml'
    @classmethod
    def setUpClass(cls) -> None:
        cls.cookie = BaseCase().get_token()

    def test_aa_rule_update(self):
        '''异常查询阻断短时高频编辑'''
        comments = self.file_data.get('comments')
        controlMode = self.file_data.get('controlMode')
        deptCode = self.file_data.get('deptCode')
        ext1 = self.file_data.get('ext1')
        ext2 = self.file_data.get('ext2')
        ext3 = self.file_data.get('ext3')
        ext4 = self.file_data.get('ext4')
        ext5 = self.file_data.get('ext5')
        ext6 = self.file_data.get('ext6')
        id = self.file_data.get('id')
        interfaceControl = self.file_data.get('interfaceControl')
        lockUser = self.file_data.get('lockUser')
        pageControl = self.file_data.get('pageControl')
        resCode = self.file_data.get('resCode')
        resMsg = self.file_data.get('resMsg')
        ruleCode = self.file_data.get('ruleCode')
        ruleDescribe = self.file_data.get('ruleDescribe')
        ruleName = self.file_data.get('ruleName')
        ruleValue1 = self.file_data.get('ruleValue1')
        ruleValue2 = self.file_data.get('ruleValue2')
        ruleValue3 = self.file_data.get('ruleValue3')
        ruleValue4 = self.file_data.get('ruleValue4')
        serialNumber = self.file_data.get('serialNumber')
        stopFlag = self.file_data.get('stopFlag')
        ret = PerRuleRequest.update(comments,
                                    controlMode,
                                    deptCode,
                                    ext1,
                                    ext2,
                                    ext3,
                                    ext4,
                                    ext5,
                                    ext6,
                                    id,
                                    interfaceControl,
                                    lockUser,
                                    pageControl,
                                    resCode,
                                    resMsg,
                                    ruleCode,
                                    ruleDescribe,
                                    ruleName,
                                    ruleValue1,
                                    ruleValue2,
                                    ruleValue3,
                                    ruleValue4,
                                    serialNumber,
                                    stopFlag,self.cookie)
        self.assertEqual('00000000', ret.code)
        self.assertIn('操作成功', ret.msg)

    def test_ab_open(self):
        '''异常查询阻断短时高频开启'''
        id = '11'
        stopFlag = 0
        ret = PerRuleRequest.start_stop(id, stopFlag, self.cookie)
        Log.info(ret)
        self.assertEqual('00000000', ret.code)
        self.assertIn('操作成功', ret.msg)

    def test_ac_report1(self):
        '''第1次查报告'''
        ret = BaseCase().per_show_report()
        self.assertIsNotNone(ret.url)

    def test_ad_report2(self):
        '''第2次查报告'''
        ret = BaseCase().per_show_report()
        self.assertIsNotNone(ret.url)

    def test_ae_report3(self):
        '''第3次查报告'''
        ret = BaseCase().per_show_report()
        self.assertIsNotNone(ret.url)

    def test_af_report4(self):
        '''第4次查报告--触犯规则'''
        ret = BaseCase().per_show_report()
        self.assertEqual('10999',ret.resultCode)
        self.assertEqual('本次查询已被阻断：原因是违反内部用户短时高频查询控制规则',ret.resultMsg)

    def test_ag_close(self):
        '''异常查询阻断关闭'''
        id = '11'
        stopFlag = 1
        ret = PerRuleRequest.start_stop(id, stopFlag, self.cookie)
        Log.info(ret)
        self.assertEqual('00000000', ret.code)
        self.assertIn('操作成功', ret.msg)

    def test_ah_get_page(self):
        '''检索'''
        curPage = self.file_data.get('curPage')
        maxSize = self.file_data.get('maxSize')
        search_EQ_userName = self.file_data.get('search_EQ_userName')
        search_EQ_userStatus = self.file_data.get('search_EQ_userStatus')
        search_EQ_aleratReason = self.file_data.get('search_EQ_aleratReason')
        search_EQ_alertStatus = self.file_data.get('search_EQ_alertStatus')
        search_EQ_orgCode = self.file_data.get('search_EQ_orgCode')
        tmp = datetime.date.today()
        search_GTE_LTE_alertDate_DATE_RANGE = '%s - %s'%(tmp,tmp)
        ret = PerAlertPageRequest.get_page(curPage,
                                            maxSize,
                                            search_EQ_userName,
                                            search_EQ_userStatus,
                                            search_EQ_alertStatus,
                                            search_EQ_aleratReason,
                                            search_EQ_orgCode,
                                            search_GTE_LTE_alertDate_DATE_RANGE,self.cookie)
        Log.info(ret)
        self.assertIsNotNone(ret.list)

    def get_page(self):
        '''返回id'''
        curPage = self.file_data.get('curPage')
        maxSize = self.file_data.get('maxSize')
        search_EQ_userName = self.file_data.get('search_EQ_userName')
        search_EQ_userStatus = self.file_data.get('search_EQ_userStatus')
        search_EQ_aleratReason = self.file_data.get('search_EQ_aleratReason')
        search_EQ_alertStatus = self.file_data.get('search_EQ_alertStatus')
        search_EQ_orgCode = self.file_data.get('search_EQ_orgCode')
        tmp = datetime.date.today()
        search_GTE_LTE_alertDate_DATE_RANGE = '%s - %s'%(tmp,tmp)
        ret = PerAlertPageRequest.get_page(curPage,
                                            maxSize,
                                            search_EQ_userName,
                                            search_EQ_userStatus,
                                            search_EQ_alertStatus,
                                            search_EQ_aleratReason,
                                            search_EQ_orgCode,
                                            search_GTE_LTE_alertDate_DATE_RANGE,self.cookie)
        Log.info(ret)
        self.assertIsNotNone(ret.list)
        return ret.list[0].id

    def test_ai_list(self):
        '''预警信息列表'''
        ret = PerAlertPageRequest.list(self.cookie)
        Log.info(ret)
        self.assertIn('预警信息列表',ret)

    def test_aj_detail(self):
        '''跳转详情页'''
        id = self.get_page()
        ret = PerAlertPageRequest.detail(id,self.cookie)
        Log.info(ret)
        self.assertIn('预警信息详情', ret)

    def test_ak_findbyid(self):
        '''详情'''
        id = self.get_page()
        ret = PerAlertPageRequest.findbyid(id,self.cookie)
        Log.info(ret)
        self.assertIn(id, ret.id)

    def addlock(self):
        '''锁用户'''
        id = self.get_page()
        ret = PerAlertPageRequest.addlock(id,self.cookie)
        Log.info(ret)
        self.assertIn('操作成功', ret.msg)
        self.assertEqual('00000000', ret.code)
        return id

    def relievereason(self):
        '''核实原因页面'''
        id = self.addlock()
        userStatus = self.file_data.get('userStatus')
        ret = PerAlertPageRequest.relievereason(id,userStatus,self.cookie)
        Log.info(ret)
        self.assertIn('解除预警信息原因',ret)
        return id

    def relieve(self):
        '''核实'''
        id = self.relievereason()
        removeAlertReason = self.file_data.get('removeAlertReason')
        ret = PerAlertPageRequest.relieve(id, removeAlertReason,self.cookie)
        Log.info(ret)
        self.assertIn('操作成功',ret.msg)
        self.assertEqual('00000000',ret.code)
        return id

    def test_al_unlock(self):
        '''解锁用户'''
        id = self.relieve()
        ret = PerAlertPageRequest.unlock(id,self.cookie)
        Log.info(ret)
        self.assertIn('操作成功', ret.msg)
        self.assertEqual('00000000', ret.code)

    def test_am_getalertreason(self):
        '''getalertreason'''
        ret = PerAlertPageRequest.getalertreason(self.cookie)
        Log.info(ret)
        self.assertEqual('',ret)

    def test_exportload_one(self):
        '''导出单条'''
        ids = self.get_page()
        search_EQ_userName = self.file_data.get('search_EQ_userName')
        search_EQ_userStatus = self.file_data.get('search_EQ_userStatus')
        search_EQ_aleratReason = self.file_data.get('search_EQ_aleratReason')
        search_EQ_alertStatus = self.file_data.get('search_EQ_alertStatus')
        search_EQ_orgCode = self.file_data.get('search_EQ_orgCode')
        tmp = datetime.date.today()
        search_GTE_LTE_alertDate_DATE_RANGE = '%s - %s' % (tmp, tmp)
        ret = PerAlertPageRequest.exportload(
                                           search_EQ_userName,
                                           search_EQ_userStatus,
                                           search_EQ_alertStatus,
                                           search_EQ_aleratReason,
                                           search_EQ_orgCode,
                                           search_GTE_LTE_alertDate_DATE_RANGE,ids, self.cookie)
        Log.info(ret)
        size = download('个人预警信息1条dhcc_per_8_alertpageDtest_exportload_one%s.xls'%time.strftime('%Y%m%d%H%M%S',time.localtime()),ret)
        Log.info('文件大小为:%s' % size)
        self.assertNotEqual(0, size)

    def get_page_more(self):
        '''返回2个id'''
        curPage = self.file_data.get('curPage')
        maxSize = self.file_data.get('maxSize')
        search_EQ_userName = ''
        search_EQ_userStatus = ''
        search_EQ_aleratReason = ''
        search_EQ_alertStatus = ''
        search_EQ_orgCode = ''
        search_GTE_LTE_alertDate_DATE_RANGE = ''
        ret = PerAlertPageRequest.get_page(curPage,
                                            maxSize,
                                            search_EQ_userName,
                                            search_EQ_userStatus,
                                            search_EQ_alertStatus,
                                            search_EQ_aleratReason,
                                            search_EQ_orgCode,
                                            search_GTE_LTE_alertDate_DATE_RANGE,self.cookie)
        Log.info(ret)
        self.assertIsNotNone(ret.list)
        return ret.list[0].id,ret.list[1].id

    def test_exportload_two(self):
        '''导出2条'''
        search_EQ_userName = ''
        search_EQ_userStatus = ''
        search_EQ_aleratReason = ''
        search_EQ_alertStatus = ''
        search_EQ_orgCode = ''
        search_GTE_LTE_alertDate_DATE_RANGE = ''
        ids = self.get_page_more()
        ret = PerAlertPageRequest.exportload(
            search_EQ_userName,
            search_EQ_userStatus,
            search_EQ_alertStatus,
            search_EQ_aleratReason,
            search_EQ_orgCode,
            search_GTE_LTE_alertDate_DATE_RANGE, ids, self.cookie)
        Log.info(ret)
        size = download('个人预警信息2条dhcc_per_8_alertpageDtest_exportload_two%s.xls' % time.strftime('%Y%m%d%H%M%S', time.localtime()), ret)
        Log.info('文件大小为:%s' % size)
        self.assertNotEqual(0, size)

    def test_exportload_all(self):
        '''导出all'''
        search_EQ_userName = ''
        search_EQ_userStatus = ''
        search_EQ_aleratReason = ''
        search_EQ_alertStatus = ''
        search_EQ_orgCode = ''
        search_GTE_LTE_alertDate_DATE_RANGE = ''
        ids = ''
        ret = PerAlertPageRequest.exportload(
            search_EQ_userName,
            search_EQ_userStatus,
            search_EQ_alertStatus,
            search_EQ_aleratReason,
            search_EQ_orgCode,
            search_GTE_LTE_alertDate_DATE_RANGE, ids, self.cookie)
        Log.info(ret)
        size = download('个人预警信息alldhcc_per_8_alertpageDtest_exportload_all%s.xls' % time.strftime('%Y%m%d%H%M%S', time.localtime()), ret)
        Log.info('文件大小为:%s' % size)
        self.assertNotEqual(0, size)


if __name__ == "__main__":
    pass